package Sequence;

public class Test0135 {
    public static void main(String[] args) {
        new Solution0135_1().candy(new int[]{1,0,2});
    }
}

class Solution0135_1 {
    public int candy(int[] ratings) {
        int length = ratings.length;
        int[] reocord = new int[length];
        reocord[0]=1;
        for (int i = 1; i < length; i++) {
            if (ratings[i]>ratings[i-1]) {
                reocord[i]=reocord[i-1]+1;
            }
            else reocord[i]=1;
        }

        int ans=reocord[length-1], last=ans;
        for (int i = length - 2; i >= 0; i--) {
            int temp = 1;
            if (ratings[i]>ratings[i+1]) temp=last+1;
            temp=Math.max(temp,reocord[i]);

            ans+=temp;
            last=temp;
        }

        return ans;
    }
}